package com.gxuwz.restaurant.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxuwz.restaurant.common.Result;
import com.gxuwz.restaurant.entity.SeatManage;
import com.gxuwz.restaurant.mapper.SeatManageMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("/seatManage")
public class SeatManageController {
    @Resource
    SeatManageMapper seatManageMapper;

    @GetMapping("/getSeat_avaliable")   //get用来查询
    public Result<?> findPage(@RequestParam(defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "10") Integer pageSize,
                              @RequestParam(defaultValue = "") String search,
                              @RequestParam(defaultValue = "") String state,
                              @RequestParam(defaultValue = "") String cleanstate
                              ) {

        LambdaQueryWrapper<SeatManage> wrapper = Wrappers.<SeatManage>lambdaQuery();
        wrapper.eq(SeatManage::getSeatState,state);
        if (StrUtil.isNotBlank(search)) {
            wrapper.like(SeatManage::getSeatNumber, search);
        }else if(StrUtil.isNotBlank(cleanstate)){
            wrapper.eq(SeatManage::getCleanstate,cleanstate);
        }


        Page<SeatManage> Page = seatManageMapper.selectPage(new Page<>(pageNum, pageSize), wrapper);


        return Result.success(Page);
    }




}
